package com.fjwt.gz.task.score;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.fjwt.gz.service.impl.StatScoreNumMonthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;



/**
 * 统计福分总数量变化与日数量变化
 *
 * @author myf
 */
@Slf4j
@Component
public class StatisticsScoreNumMonthTask {

    @Autowired
    private StatScoreNumMonthService statScoreNumMonthService;


//    @Scheduled(cron = "0 0 1 * * ?")
    @Transactional(rollbackFor = Exception.class)
    public void start() {
        log.info("开始进入统计福分数量变化定时任务，开始时间:{}", DateUtil.now());
        // 获取前一天的日期
        DateTime lastMonth = DateUtil.lastMonth();

        try {
            statScoreNumMonthService.getScoreNumMonthStatistics(lastMonth);
            log.info("积分统计任务执行成功，统计日期：{}", DateUtil.now());
        } catch (Exception e) {
            log.error("积分统计任务执行失败，日期：{}", DateUtil.now(), e);
        }

        log.info("结束统计福分数量变化定时任务，结束时间:{}", DateUtil.now());
    }

}
